package com.itrip.biz.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itrip.beans.pojo.HotelRoom;
import com.itrip.beans.pojo.HotelTempStore;
import com.itrip.beans.vo.StoreVO;
import com.itrip.biz.service.HotelTempStoreService;
import com.itrip.dao.HotelTempStoreMapper;
import com.itrip.utils.util.EmptyUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 实时库存表 服务实现类
 * </p>
 *
 * @author 周勉
 * @since 2020-02-28
 */
@Service
public class HotelTempStoreServiceImpl extends ServiceImpl<HotelTempStoreMapper, HotelTempStore> implements HotelTempStoreService {
    @Resource
    private HotelTempStoreMapper hotelTempStoreMapper;
    @Override
    public List<StoreVO> queryRoomStore(Map<String, Object> param) throws Exception {
//        hotelTempStoreMapper.flushStore(param);
        return hotelTempStoreMapper.queryRoomStore(param);
    }

    @Override
    public boolean validateRoomStore(Map<String, Object> param) throws Exception {
        Integer count = (Integer) param.get("count");
//        hotelTempStoreMapper.flushStore(param);
        List<StoreVO> storeVOList = hotelTempStoreMapper.queryRoomStore(param);
        if(EmptyUtils.isEmpty(storeVOList)){
            return false;
        }
        for (StoreVO vo : storeVOList) {
            if (vo.getStore() < count) {
                return false;
            }
        }
        return true;
    }
}
